package canss.webservice.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.beehive.controls.api.bean.Control;

import canss.supports.basic;
import canss.webservice.service.PortalIntraWebServiceControl;
import canss.webservice.service.PortalIntraWebServiceControlBean;

public class svtGetKeyDesc extends javax.servlet.http.HttpServlet implements
		javax.servlet.Servlet
{
	private static final long serialVersionUID = 4663192623595220229L;

	public svtGetKeyDesc()
	{
		super();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		doPost(request, response);
	}

	@Control
	PortalIntraWebServiceControl control; // control = (control==null)?new

	// PortalIntraWebServiceControlBean():control;

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter out = response.getWriter();
		control = (control == null) ? new PortalIntraWebServiceControlBean() : control;

		String _pid = request.getParameter("_pid");
		String _key = request.getParameter("_key");
		String _notxml = request.getParameter("_notxml");

		if (_notxml != null)
		{
		} else
		{// in xml
			out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
			weblogic.application.utils.XMLWriter writer = new weblogic.application.utils.XMLWriter(out);
			writer.addElement("canss");
			writer.addElement("canssPerson_Person");
			if (!basic.isEmpty(_key))
			{
				writer.addElement("canssPerson_type");
				writer.addAttribute("key", _key);
				writer.closeElement();
				writer.addElement("js_blanket_s", "{");
				writer.addElement("js_blanket_e", "}");
				writer.addElement("js_href_cooliris", response.encodeRedirectURL("coolirisSamplePage.jsp?_param="+URLEncoder.encode("http://canss.net/CANSSWebService/svtContentsPort?_cooliris=1&_channelname=channel1&_key="+_key, "utf-8")));
			}
			writer.addElement("canssPerson_id", _pid);
			writer.closeElement();
			writer.finish();
		}
	}
}